package com.shopoo.behavior.infrastructure.database.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopoo.behavior.infrastructure.database.dataobject.TBehaviorRead;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @Description: 阅读记录持久化
 * @Package com.szmengran.behavior.mapper
 * @date Mar 4, 2019 1:07:31 PM
 * @author <a href="mailto:android_li@sina.cn">Joe</a>
 */
@Mapper
public interface ReadMapper extends BaseMapper<TBehaviorRead> {

    /**
     * 计算指定活动某个ip的阅读量
     * @param promotionid
     * @param ip
     * @return
     * @throws Exception 
     * @author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @Select("select count(1) from t_behavior_read where promotionid=#{promotionid} and ip=#{ip}")
    int readCountByIP(@Param("promotionid") String promotionid, @Param("ip") String ip);
    
    /**
     * 计算指定活动某个openid的阅读量
     * @param promotionid
     * @param openid
     * @return
     * @throws Exception 
     * @author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @Select("select count(1) from t_behavior_read where promotionid=#{promotionid} and openid=#{openid}")
    int readCountByOpenid(@Param("promotionid") String promotionid, @Param("openid") String openid);
}
